<extend name="./public/frame.html"/>
<block name="content">
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.css">
    <div class="layer_content">
        <div class="layer_form">
            <div class="down_icon"></div>
            <div class="layer_div">
                <div class="layer_tit">
                    手机号：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180" id="passenger_phone" placeholder="手机号搜索">
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    订单号：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180" id="complaint_sn" placeholder="订单号搜索">
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    投诉时间：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180 date" id="start" placeholder="投诉时间（开始）">
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    投诉时间：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180 date" id="end" placeholder="投诉时间（结束）">
                </div>
            </div>
            <div class="button_search">
                <button class="layui-btn" data-type="search" style="float: right;margin-right: 52px;">搜索</button>
            </div>
        </div>
    </div>
    <table class="layui-table" lay-size="lg" lay-data="{width:'auto', height:'auto', url:'{:url('Custom/complaint')}', page: true, limit: 10, id:'test'}" lay-filter="test">
        <thead>
            <tr>
                <th lay-data="{field:'cid', width:80, fixed: true, align:'center'}">cid</th>
                <th lay-data="{field:'complaint_sn', width:200, align:'center'}">订单号</th>
                <th lay-data="{field:'user_phone', width:120, align:'center'}">乘客手机号</th>
                <th lay-data="{field:'content', width:200, align:'center'}">投诉内容</th>
                <th lay-data="{field:'time', width:160, align:'center'}">投诉时间</th>
                <th lay-data="{field:'driver_name', width:100, align:'center'}">司机姓名</th>
                <th lay-data="{field:'appeal_content', width:120, align:'center'}">申诉内容</th>
                <th lay-data="{field:'user_name', width:120, align:'center'}">客服管理员</th>
                <th lay-data="{field:'result', width:120, align:'center'}">处理内容</th>
                <th lay-data="{field:'type', toolbar: '#selects',width:150}">类型操作</th>
                <th lay-data="{toolbar: '#barDemo', width:280, align:'center'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="selects">
        <select class="form-control selects layui-input-block" data-id="{{d.cid}}" name="" lay-ignore
                style="margin-left: 0">
            <option value="0">请选择投诉类型</option>
            <option value="1" {{# if(d.type== 1){ }} selected {{# } }}>成交率扣错</option>
            <option value="2" {{# if(d.type== 2){ }} selected {{# } }}>车费有问题</option>
            <option value="3" {{# if(d.type== 3){ }} selected {{# } }}>其他</option>
        </select>
    </script>
    <script type="text/html" id="barDemo">
        {{# if(d.is_deal == 0){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled" style="width: 82px">不予处理</a>
        {{# }else if(d.is_deal == 1){ }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="deal" style="width: 82px">未推送给司机</a>
        {{# }else if(d.is_deal == 2){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled" style="width: 82px">已推送司机</a>
        {{# }else if(d.is_deal == 3){ }}
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="dealing" style="width: 82px">司机申诉中..</a>
        {{# }else if(d.is_deal == 4){ }}
        <a class="layui-btn layui-btn-xs layui-btn-normal" style="width: 82px">处理完成</a>
        {{# } }}
        {{# if(d.money == 0){ }}
        <a class="layui-btn layui-btn-xs" lay-event="fk" style="width: 46px">罚款</a>
        {{# }else { }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="yfk" style="width: 46px">已罚款</a>
        {{# } }}
        <!-- 	{{# if(d.point == 0){ }}
            <a class="layui-btn layui-btn-xs" lay-event="ff">罚分</a>
            {{# }else { }}
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="yff">已罚分</a>
            {{# } }} -->
        <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>

    </script>
    <div id="htmls" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">是否罚款</label>
            <div class="layui-input-block">
                <input type="radio" name="punish" value="1" title="罚款">
                <input type="radio" name="punish" value="0" title="不罚款" checked>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">处理内容</label>
            <div class="layui-input-block">
                <textarea name="result" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
    </div>
    <script>
        layui.use(['layer', 'table', 'form','laydate'], function () {
            var table = layui.table,laydate = layui.laydate;
            lay('.date').each(function(){
                laydate.render({
                    elem: this
                    ,type: 'date'
                    ,trigger: 'click'
                });
            });
            //监听工具条
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                var cid = data.cid;
                //罚款出来
                if (obj.event === 'fk') {
                    // var cid = data.cid;
                    layer.prompt({
                        formType: 3,
                        value: '',
                        title: '请输入值罚款金额，不要输入汉字',
                        area: ['200px', '150px'] //自定义文本域宽高
                    }, function (value, index, elem) {
                        layer.close(index);
                        if (value != '') {
                            $.post('/admin/Custom/money', {'cid': cid, 'money': value}, function (res) {
                                console.log(res);
                                switch (res.status){
                                    case 1:
                                        obj.del();
                                        alert(res.msg);
                                        window.location.reload();
                                        ajax_money(cid,value);
                                        break;
                                    default:
                                        layer.alert(res['msg'],{icon: 5});
                                        break;
                                }
                            }, 'json')
                        }
                    });
                }
                else if (obj.event === 'deal') {
                    if(data.type==''){
                        layer.alert('请先选择投诉类型',{icon:2});
                        return false;
                    }
                    var deal = 1;
                    layer.open({
                        icon:3
                        ,content: '确定推送吗?'
                        , btn: ['确定', '不予处理', '取消'] //可以无限个按钮
                        , yes: function (index, layero) {
                            deal = 2;
                            send_complaint(cid, deal);
                            layer.close(index);
                        }
                        , btn2: function (index, layero) {
                            //按钮【按钮二】的回调
                            deal = 0;
                            send_complaint(cid, deal);
                            layer.close(index);
                        }
                        , btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                        , cancel: function () {
                            //右上角关闭回调
                        }
                    })
                }
                else if (obj.event === 'dealing') {
                    layer.prompt({
                        title: '处理内容'
                        , formType: 2
                    }, function (text, index) {
                        if (text === '') {
                            layer.msg('处理内容不能为空');
                        }
                        $.post("{:url('Custom/dealing')}", {'cid': cid, 'type': 2, 'result': text}, function (res) {
                            switch (res['status']){
                                case 1:
                                    window.location.reload();
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        }, 'json')
                    });
                }
                else if (obj.event === 'look') {
                    //查看页面
                    layer.open({
                        type: 2,
                        title: '投诉详情',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['90%', '90%'],
                        content: '{:url("/admin/custom/look","cid=")}' + cid //iframe的url
                    });

                }
            });
            var $ = layui.jquery, active = {
                search: function () {
                    var complaint_sn = $.trim($('#complaint_sn').val()),
                        start = $('#start').val(),
                        end = $('#end').val(),
                        passenger_phone = $.trim($('#passenger_phone').val()),
                        reset = $('#reset');
                    if(start||end||complaint_sn||passenger_phone){
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('test',{
                            url: '/admin/Custom/complaint',
                            where: {
                                start : start,
                                end : end,
                                complaint_sn : complaint_sn,
                                passenger_phone : passenger_phone,
                            } //设定异步数据接口的额外参数
                        });
                    }else{
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        layer.alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('test',{
                            url: '/admin/Custom/complaint', where:{}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });
                    $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            function send_complaint(cid, deal) {
                var url = "{:url('set_complaint')}";
                $.post(url, {'cid': cid, 'deal': deal}, function (res) {
                    switch (res['status']){
                        case 1:
                            window.location.reload();
                            break;
                        default:
                            layer.alert(res['msg'],{icon: 5});
                            break;
                    }
                }, 'json')
            }
        });


        $(document).on('change', '.selects', function () {
            var type = $(this).val();
            var cid = $(this).data('id');
            $.post("{:url('custom/ajax_type')}", {"type": type, "cid": cid}, function (res) {
                switch (res['status']){
                    case 1:
                        layer.alert(res['msg'],{icon: 1});
                        break;
                    default:
                        layer.alert(res['msg'],{icon: 5});
                        break;
                }

            }, 'json')
        });


        function ajax_money(cid, value) {
            $.post('/admin/Custom/ajax_money',{'cid': cid, 'money': value},function(res){
                if(res.code === 200) {
                    console.log(res.msg);
                } else {
                    console.log(res.msg);
                }
            });
        }
    </script>
</block>
